# -*- coding: UTF-8 -*-
# @create  : 2024/8/28 14:31
# @Author  : 天空之城
# @File    : server.py
from address_normalizer.app import create_app
from address_normalizer.app.config import logger
from address_normalizer.app.config import HTTP_HOST, HTTP_PORT
from address_normalizer.app.config import CHINA_REGIONS_JSON, PATTERN_FILE, EXCEL_FILE, PROVINCE_CITY_DISTRICT, \
    JIEBA_FILE, DEFAULT_FREQUENCY
from address_normalizer.app.utils.conversion import convert_regions_to_patterns, process_and_save_area_data, \
    create_jieba_dict, load_data_from_json

this_app = create_app()
logger.info("启动服务!")
process_and_save_area_data(EXCEL_FILE, PROVINCE_CITY_DISTRICT, CHINA_REGIONS_JSON)
convert_regions_to_patterns(CHINA_REGIONS_JSON, PATTERN_FILE)
create_jieba_dict(load_data_from_json(PATTERN_FILE), output_file=JIEBA_FILE, default_frequency=DEFAULT_FREQUENCY)
logger.info("文件更新完成！")
this_app.run(host=HTTP_HOST, port=HTTP_PORT)
